﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ParangonBiz.Data;
using ParangonBiz.Tools;

namespace ParangonBiz
{
    public partial class Default : System.Web.UI.Page
    {
        private void FillMainContent()
        {
            List<SiteContent> sc = SiteContent.ListAllContent((int)EnumHelper.ContentType.Main);
            if (sc != null)
            {
                SiteContent mainSiteContent = sc.SingleOrDefault();
                if (mainSiteContent != null)
                {
                    lblMainContentTitle.Text = mainSiteContent.Title;
                    lMainContent.Text = mainSiteContent.Content;
                }
            }
        }

        private void FillLastNewsList()
        {
            List<SiteContentType> sctList = SiteContentType.GetAllContentTypes();
            if (sctList != null)
            {
                SiteContentType sct = sctList.FirstOrDefault(i => i.IsShortList == true);
                if (sct != null)
                {
                    List<SiteContent> scList = SiteContent.ListNumberedContent(sct.SiteContentTypeId, 3);
                    if (scList != null)
                    {
                        rptLastMessages.DataSource = scList.OrderByDescending(i => i.CreateDate);
                        rptLastMessages.DataBind();
                    }
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                FillMainContent();
                FillLastNewsList();
            }
        }
    }
}